package com.wechat.page;

import com.swak.fx.support.FXMLView;
import com.swak.fx.support.Window;
import com.swak.fx.support.ui.UIAction;
import com.swak.ui.Event;
import com.swak.ui.Events;

import javafx.scene.input.MouseEvent;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;

/**
 * 系统托盘
 * 
 * @author lifeng
 */
@FXMLView(title = "首页", value = "PopupMenu.fxml", css = "PopupMenu.css", stageStyle = "TRANSPARENT")
public class PopupMenu extends Window {

	private UIAction settingBtn;
	private UIAction helpBtn;
	private UIAction aboutBtn;
	private UIAction exitBtn;

	public PopupMenu() {
		this.settingBtn = new UIAction().setText("设置");
		this.helpBtn = new UIAction().setText("帮助");
		this.aboutBtn = new UIAction().setText("关于");
		this.exitBtn = new UIAction().setText("退出");
	}

	@Override
	public void initializeParts() {
		super.initializeParts();

		this.addChild(this.settingBtn);
		this.addChild(this.helpBtn);
		this.addChild(this.aboutBtn);
		this.addChild(this.exitBtn);

		this.initNode(this.settingBtn, 0);
		this.initNode(this.helpBtn, 1);
		this.initNode(this.aboutBtn, 2);
		this.initNode(this.exitBtn, 3);
	}

	private void initNode(UIAction btn, int row) {
		GridPane.setConstraints(btn, 0, row);
		GridPane.setHgrow(btn, Priority.ALWAYS);
		GridPane.setVgrow(btn, Priority.ALWAYS);
	}

	// 禁止窗口事件
	@Override
	public void setupEventHandlers() {
		this.exitBtn.addEventHandler(MouseEvent.MOUSE_CLICKED, (e) -> {
			Events.post(Event.EXIT);
		});
	}

	// 禁止窗口事件
	@Override
	public void setupValueChangedListeners() {
	}
}
